package com.yboot.starter.mybatis.core.plugin;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import net.sf.jsqlparser.statement.select.OrderByElement;

import java.util.List;

public class PaginationInnerExtendInterceptor extends PaginationInnerInterceptor {
    public PaginationInnerExtendInterceptor() {
    }

    /**
     * column 驼峰转下划线
     * @param orderList
     * @param orderByElements
     * @return
     */
    protected List<OrderByElement> addOrderByElements(List<OrderItem> orderList, List<OrderByElement> orderByElements) {
        orderList.forEach((i) -> {
            i.setColumn(StrUtil.toUnderlineCase(i.getColumn()));
        });
        return super.addOrderByElements(orderList, orderByElements);
    }
}